define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'users/index',
//                    add_url: 'users/add',
//                    edit_url: 'users/edit',
//                    del_url: 'users/del',
//                    multi_url: 'users/multi',
                    table: 'users',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'user_id',
                sortName: 'user_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'wx_nick_name', title: __('Wx_nick_name')},
//                        {field: 'wx_open_id', title: __('Wx_open_id')},
                        {field: 'wx_number', title: __('Wx_number')},
                        {field: 'phone', title: __('Phone')},
                        {field: 'face', formatter: Table.api.formatter.image, title: __('Face')},
                        {field: 'real_name', title: __('Real_name')},
                        {field: 'sex', title: __('Sex'), visible:false, searchList: {"0":__('女'),"1":__('男')}},
                        {field: 'sex_text', title: __('Sex'), operate:false},
                        {field: 'company', title: __('Company')},
                        {field: 'position', title: __('Position')},
                        {field: 'constellation', title: __('Constellation')},
                        {field: 'brithday', title: __('Brithday'),operate: false},
//                        {field: 'user_token', title: __('User_token')},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true,operate: false},
                       {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                    name: 'detail',
                                    text: __('Detail'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'users/detail'
                                }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});